<template>
  <div class="register">
    <div class="registerLogo">
      {{platformName}}
    </div>
    <div class="registerCon">
      <div class="tregisterTab">
        <ul>
          <li :class="nextStep == 1 ? 'active' : ''">
            <div><span>1</span>个人信息</div>
            <img src="../assets/img/register1.jpg" /><img
              class="on"
              src="../assets/img/register03.jpg"
            />
          </li>
          <li :class="nextStep == 2 ? 'active' : ''">
            <div><span>2</span>公司信息</div>
            <img src="../assets/img/register2.jpg" /><img
              class="on"
              src="../assets/img/register02.jpg"
            />
          </li>
          <li :class="nextStep == 3 ? 'active' : ''">
            <div><span>3</span>申请审核</div>
            <img src="../assets/img/register3.jpg" /><img
              class="on"
              src="../assets/img/register01.jpg"
            />
          </li>
        </ul>
      </div>
      <el-form
        v-if="nextStep == 1"
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        class="demo-ruleForm"
        label-width="160px"
        style="margin-top: 180px"
      >
        <el-form-item label="登录账号" prop="username">
          <el-input v-model="ruleForm.username" @blur="checkBlur($event)"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input :type="passwordShow" v-model="ruleForm.password"></el-input>
          <img v-if="seeEyeShow" class="seeEye" @click="seeEye()" src="../assets/img/eyes.png" alt="">
          <img v-if="!seeEyeShow" class="seeEye" @click="seeEyes()" src="../assets/img/eye.png" alt="">
        </el-form-item>
        <el-form-item label="确认密码" prop="confirmPassword">
          <el-input :type="passwordShow" v-model="ruleForm.confirmPassword"></el-input>
          <img v-if="seeEyeShow" class="seeEye" @click="seeEye()" src="../assets/img/eyes.png" alt="">
          <img v-if="!seeEyeShow" class="seeEye" @click="seeEyes()" src="../assets/img/eye.png" alt="">
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="ruleForm.phone"></el-input>
        </el-form-item>
        <el-form-item label="验证码" prop="smsCode">
          <el-input v-model="ruleForm.smsCode">
            <template #suffix>
              <div class="suffix-button" :class="{ 'on': timeNumbers }" @click="sendCode">{{ codeMessage }}</div>
            </template>
          </el-input>
        </el-form-item>
        <!-- <button class="suffix-button" :class="{ 'timeNumbers': on }" @click="sendCode">{{ codeMessage }}</button> -->
        <el-form-item>
          <div class="login-btn">
            <el-button type="primary" @click="submitForm('ruleForm')"
              >下一步</el-button
            >
          </div>
        </el-form-item>
      </el-form>
      <el-form
        v-else-if="nextStep == 2"
        :model="ruleBusiness"
        :rules="rules"
        ref="ruleForms"
        class="demo-ruleForm"
        label-width="160px"
        style="margin-top: 180px"
      >
        <el-form-item label="公司名称" prop="name">
          <el-input v-model="ruleBusiness.name" @blur="checkBlurs($event)"></el-input>
        </el-form-item>
        <el-form-item label="公司类型" prop="businessType">
          <el-select
            v-model="ruleBusiness.businessType"
            ref="businessType"
            placeholder="请选择"
          >
            <el-option
              v-for="item in companyTypeList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            <!-- <el-option
              v-for="item in $store.state.companyTypeArr"
              :key="item.dataCode"
              :label="item.dataMsg"
              :value="item.dataCode"
            > -->
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="行业" prop="industyCode">
          <el-select
            v-model="ruleBusiness.industyCode"
            ref="industy"
            placeholder="请选择"
          >
            <el-option
              v-for="item in industryList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
            <!-- <el-option
              v-for="item in $store.state.industryArr"
              :key="item.dataCode"
              :label="item.dataMsg"
              :value="item.dataCode"
            >
            </el-option> -->
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="开户账号" prop="bankNo">
          <el-input v-model="ruleBusiness.bankNo"></el-input>
        </el-form-item>
        <el-form-item label="开户行">
          <el-input v-model="ruleBusiness.bankName"></el-input>
        </el-form-item> -->
        <el-form-item label="联系人姓名">
          <el-input v-model="ruleBusiness.linkManName"></el-input>
        </el-form-item>
        <el-form-item label="联系人身份证号">
          <el-input v-model="ruleBusiness.linkManIdcard"></el-input>
        </el-form-item>
        <el-form-item
          class="contactsPic"
          label="联系人身份证正面"
        >
          <el-input v-model="ruleBusiness.linkIdcardFrondUrl"></el-input>
          <el-upload
            accept="image/png,image/jpeg"
            action="#"
            list-type="picture-card"
            :auto-upload="true"
            :multiple="false"
            :limit="1"
            :file-list="fileList.linkIdcardFrondUrl"
            :http-request="
              (file) => uploadPhotoFile(file, 'linkIdcardFrondUrl')
            "
            ref="idPositive"
          >
            <template #default>
              <i class="el-icon-picture-outline"></i>
            </template>
            <template #file="{ file }">
              <div>
                <img
                  class="el-upload-list__item-thumbnail"
                  :src="file.url"
                  alt=""
                />
                <span class="el-upload-list__item-actions">
                  <span
                    class="el-upload-list__item-delete"
                    @click="removePhotoFile('idPositive', 'linkIdcardFrondUrl')"
                  >
                    <i class="el-icon-delete"></i>
                  </span>
                </span>
              </div>
            </template>
          </el-upload>
          <b>（支持JPG、PNG格式的文件，且大小不超过6M）</b>
        </el-form-item>
        <el-form-item
          class="contactsPic"
          label="联系人身份证反面"
          :before-upload="beforeAvatarUpload"
        >
          <el-input v-model="ruleBusiness.linkIdcardBackUrl"></el-input>
          <el-upload
            action="#"
            accept="image/png,image/jpeg"
            list-type="picture-card"
            :auto-upload="true"
            :multiple="false"
            :limit="1"
            :file-list="fileList.linkIdcardBackUrl"
            :http-request="(file) => uploadPhotoFile(file, 'linkIdcardBackUrl')"
            ref="idOther"
          >
            <template #default>
              <i class="el-icon-picture-outline"></i>
            </template>
            <template #file="{ file }">
              <div>
                <img
                  class="el-upload-list__item-thumbnail"
                  :src="file.url"
                  alt=""
                />
                <span class="el-upload-list__item-actions">
                  <span
                    class="el-upload-list__item-delete"
                    @click="removePhotoFile('idOther', 'linkIdcardBackUrl')"
                  >
                    <i class="el-icon-delete"></i>
                  </span>
                </span>
              </div>
            </template>
          </el-upload>
          <b>（支持JPG、PNG格式的文件，且大小不超过6M）</b>
        </el-form-item>
        <el-form-item label="法人姓名">
          <el-input v-model="ruleBusiness.legalName"></el-input>
        </el-form-item>
        <el-form-item label="法人身份证号">
          <el-input v-model="ruleBusiness.legalIdcard"></el-input>
        </el-form-item>
        <el-form-item
          class="contactsPic"
          label="法人身份证正面"
        >
          <el-input v-model="ruleBusiness.legalIdcardFrondUrl"></el-input>
          <el-upload
            action="#"
            accept="image/png,image/jpeg"
            list-type="picture-card"
            :auto-upload="true"
            :multiple="false"
            :limit="1"
            :file-list="fileList.legalIdcardFrondUrl"
            :http-request="
              (file) => uploadPhotoFile(file, 'legalIdcardFrondUrl')
            "
            ref="farenPositive"
          >
            <template #default>
              <i class="el-icon-picture-outline"></i>
            </template>
            <template #file="{ file }">
              <div>
                <img
                  class="el-upload-list__item-thumbnail"
                  :src="file.url"
                  alt=""
                />
                <span class="el-upload-list__item-actions">
                  <span
                    class="el-upload-list__item-delete"
                    @click="
                      removePhotoFile('farenPositive', 'legalIdcardFrondUrl')
                    "
                  >
                    <i class="el-icon-delete"></i>
                  </span>
                </span>
              </div>
            </template>
          </el-upload>
          <b>（支持JPG、PNG格式的文件，且大小不超过6M）</b>
        </el-form-item>
        <el-form-item
          class="contactsPic"
          label="法人身份证反面"
        >
          <el-input v-model="ruleBusiness.legalIdcardBackUrl"></el-input>
          <el-upload
            action="#"
            accept="image/png,image/jpeg"
            list-type="picture-card"
            :auto-upload="true"
            :multiple="false"
            :limit="1"
            :file-list="fileList.legalIdcardBackUrl"
            :http-request="
              (file) => uploadPhotoFile(file, 'legalIdcardBackUrl')
            "
            ref="farenOther"
          >
            <template #default>
              <i class="el-icon-picture-outline"></i>
            </template>
            <template #file="{ file }">
              <div>
                <img
                  class="el-upload-list__item-thumbnail"
                  :src="file.url"
                  alt=""
                />
                <span class="el-upload-list__item-actions">
                  <span
                    class="el-upload-list__item-delete"
                    @click="removePhotoFile('farenOther', 'legalIdcardBackUrl')"
                  >
                    <i class="el-icon-delete"></i>
                  </span>
                </span>
              </div>
            </template>
          </el-upload>
          <b>（支持JPG、PNG格式的文件，且大小不超过6M）</b>
        </el-form-item>
        <el-form-item label="社会统一信用代码" prop="socialCreditCode">
          <el-input v-model="ruleBusiness.socialCreditCode"></el-input>
        </el-form-item>
        <el-form-item
          class="contactsPic"
          label="上传营业执照"
          prop="licenseUrl"
        >
          <el-input v-model="ruleBusiness.licenseUrl"></el-input>
          <el-upload
            action="#"
            list-type="picture-card"
            :auto-upload="true"
            :multiple="false"
            :limit="1"
            :file-list="fileList.licenseUrl"
             accept="image/png,image/jpeg,application/pdf"
            :http-request="(file) => uploadPhotoFile(file, 'licenseUrl')"
            ref="idlicenseUrl"
          >
            <template #default>
              <i class="el-icon-picture-outline"></i>
            </template>
            <template #file="{ file }">
              <div>
                <img
                  class="el-upload-list__item-thumbnail"
                  :src="file.url"
                  v-if="file.url.indexOf('.PDF') == -1 && file.url.indexOf('.pdf') == -1"
                  alt=""
                />
                <img
                  class="el-upload-list__item-thumbnail"
                  src="../assets/img/pdf.png"
                  v-else
                  style="width: 40px; margin: 9px 0 0 18px;"
                  alt=""
                />
                <span class="el-upload-list__item-actions">
                  <span
                    class="el-upload-list__item-delete"
                    @click="removePhotoFile('idlicenseUrl', 'licenseUrl')"
                  >
                    <i class="el-icon-delete"></i>
                  </span>
                </span>
              </div>
            </template>
          </el-upload>
          <b>（支持JPG、PNG、PDF格式的文件，且大小不超过6M）</b>
        </el-form-item>
        <el-form-item class="contactsPic" label="上传合同" prop="agreementUrl">
          <el-input v-model="ruleBusiness.agreementUrl"></el-input>
          <el-upload
            action="#"
            list-type="picture-card"
            :auto-upload="true"
            :multiple="false"
            :limit="1"
            :file-list="fileList.agreementUrl"
            accept="image/png,image/jpeg,application/pdf"
            :http-request="(file) => uploadPhotoFile(file, 'agreementUrl')"
            ref="idagreementUrl"
          >
            <template #default>
              <i class="el-icon-picture-outline"></i>
            </template>
            <template #file="{ file }">
              <div>
                <img
                  class="el-upload-list__item-thumbnail"
                  :src="file.url"
                  v-if="file.url.indexOf('.PDF') == -1 && file.url.indexOf('.pdf') == -1"
                  alt=""
                />
                <img
                  class="el-upload-list__item-thumbnail"
                  src="../assets/img/pdf.png"
                  v-else
                  style="width: 40px; margin: 9px 0 0 18px;"
                  alt=""
                />
                <span class="el-upload-list__item-actions">
                  <span
                    class="el-upload-list__item-delete"
                    @click="removePhotoFile('idagreementUrl', 'agreementUrl')"
                  >
                    <i class="el-icon-delete"></i>
                  </span>
                </span>
              </div>
            </template>
          </el-upload>
          <b>（支持JPG、PNG、PDF格式的文件，且大小不超过6M）</b>
        </el-form-item>
        <el-form-item
          class="contactsPic"
          label="资质附件"
          prop="qualAttachmentUrl"
        >
          <el-input v-model="ruleBusiness.qualAttachmentUrl"></el-input>
          <el-upload
            action="#"
            list-type="picture-card"
            :auto-upload="true"
            :multiple="false"
            :limit="1"
            accept="image/png,image/jpeg,application/pdf"
            :file-list="fileList.qualAttachmentUrl"
            :http-request="(file) => uploadPhotoFile(file, 'qualAttachmentUrl')"
            ref="qualAttac"
          >
            <template #default>
              <i class="el-icon-picture-outline"></i>
            </template>
            <template #file="{ file }">
              <div>
                <img
                  class="el-upload-list__item-thumbnail"
                  :src="file.url"
                  v-if="file.url.indexOf('.PDF') == -1 && file.url.indexOf('.pdf') == -1"
                  alt=""
                />
                <img
                  class="el-upload-list__item-thumbnail"
                  src="../assets/img/pdf.png"
                  v-else
                  style="width: 40px; margin: 9px 0 0 18px;"
                  alt=""
                />
                <span class="el-upload-list__item-actions">
                  <span
                    class="el-upload-list__item-delete"
                    @click="removePhotoFile('qualAttac', 'qualAttachmentUrl')"
                  >
                    <i class="el-icon-delete"></i>
                  </span>
                </span>
              </div>
            </template>
          </el-upload>
          <b>（支持JPG、PNG、PDF格式的文件，且大小不超过6M）</b>
        </el-form-item>
        <el-form-item>
          <div class="login-btn">
            <el-button type="primary" @click="examine('ruleForms')"
              >申请审核</el-button
            >
            <b>
              <router-link to="/register"
                >审核通过后，您将收到短信通知，请注意相关短信信息</router-link
              >
            </b>
          </div>
        </el-form-item>
      </el-form>
      <div v-else class="examine">
        <img src="../assets/img/register7.jpg" />
        <b v-if="nextSteps == 2">审核未通过！原因：上传资料不清楚！<a @click="getNextStep">修改资料</a></b>
        <b v-if="nextSteps == 3">申请已提交，请耐心等待审核哦！</b>
      </div>
    </div>
  </div>
</template>

<script>
import {Encrypt} from '../utils/crypto'
export default {
  data() {
    var validatorUser = (rule, value, callback) => {
      if(this.nextSteps == 0) {
        return /^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^\w\s]).{6,}$/.test(value);
      }else {
        if (!value) {
          return callback(new Error('请输入社会统一信用代码'));
        }
        // 手机号正则校验，这里使用了一个简单的正则，你也可以根据需要调整它
        const phoneReg = /^[a-zA-Z0-9_-]{18,18}$/;
        if (!phoneReg.test(value)) {
          callback(new Error('请输入有效的社会统一信用代码'));
        } else {
          callback();
        }
      }
    };
    return {
      passwordShow: "password",
      seeEyeShow: true,
      fileList: {
        licenseUrl: [],
        linkIdcardFrondUrl: [],
        linkIdcardBackUrl: [],
        legalIdcardFrondUrl: [],
        legalIdcardBackUrl: [],
        agreementUrl: [],
        qualAttachmentUrl: []
      },
      businessLoginName: 0,
      businessName: 0,
      timeNumbers: false,
      logoUrl: '',
      platformName: '',
      nextStep: 2,
      businessPo: [],
      imageUrl:'',
      nextSteps: 0,
      fileData: null,
      ruleForm: {
        username: "", //登录账号
        password: "", // 密码
        confirmPassword: "", // 确认密码
        phone: "", // 手机号
        smsCode: "", // 验证码
      },
      ruleForms: {
        username: "", //登录账号
        password: "", // 密码
        confirmPassword: "", // 确认密码
        phone: "", // 手机号
        smsCode: "", // 验证码
      },
      ruleBusiness: {
        //  企业信息
        // bankNo: "", // 开户账号
        // bankName: "", // 开户行
        name: "", // 企业名称
        businessType: "", // 企业类型
        businessTypeMsg: "", // 企业类型msg
        industyCode: "", // 所属行业
        industyMsg: "", // 所属行业msg
        licenseUrl: "", // 营业执照路径
        agreementUrl: "", // 合同路径
        qualAttachmentUrl: "", // 资质附件
        linkIdcardFrondUrl: "", // 联系人身份证正面
        linkIdcardBackUrl: "", // 联系人身份证反面
        legalIdcardFrondUrl: "", // 身份证正面
        legalIdcardBackUrl: "", // 身份证反面
        legalName: "", // 法人姓名
        legalIdcard: "", // 法人身份证号
        linkManName: "", // 联系人姓名
        linkManIdcard: "", // 联系人身份证号
        socialCreditCode: "",// 社会统一信用代码
      },
      // 公司类型
      companyTypeList: [
        {
          value: "0",
          label: "其他",
        },
        {
          value: "1",
          label: "个体工商户",
        },
        {
          value: "2",
          label: "有限责任公司",
        },
        {
          value: "3",
          label: "股份有限公司",
        },
        {
          value: "4",
          label: "合伙企业",
        },
        {
          value: "5",
          label: "个人独资企业",
        },
      ],
      // 行业
      industryList: [
        {
          value: "1",
          label: "广告",
        },
        {
          value: "2",
          label: "中介",
        },
        {
          value: "3",
          label: "美发",
        },
        {
          value: "4",
          label: "物流运输",
        },
        {
          value: "5",
          label: "培训",
        },
        {
          value: "6",
          label: "营销",
        },
        {
          value: "7",
          label: "机械组装",
        },
        {
          value: "8",
          label: "新媒体",
        },
        {
          value: "9",
          label: "其他服务行业",
        },
      ],
      rules: {
        username: [
          { required: true, message: "请输入登录账号", trigger: "blur" },
          {
            min: 3,
            max: 20,
            message: "长度在 3 到 20 个字符",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { validator: validatorUser, message: '密码长度至少6位，必须包含字母、数字和特殊字符（?=.*@)' }
        ],
        confirmPassword: [
          { required: true, message: "请确认密码", trigger: "blur" },
          { min: 3, max: 20, message: '密码长度至少6位，必须包含字母、数字和特殊字符（?=.*@)' }
        ],
        phone: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          {
            min: 11,
            max: 11,
            message: "长度在 11 到 15 个字符",
            trigger: "blur",
          },
        ],
        smsCode: [
          { required: true, message: "请输入验证码", trigger: "blur" },
          { min: 6, max: 6, message: "长度在 6 到 6 个字符", trigger: "blur" },
        ],
        name: [
          { required: true, message: "请输入公司名称", trigger: "blur" },
          {
            min: 3,
            max: 40,
            message: "长度在 3 到 40 个字符",
            trigger: "blur",
          },
        ],
        businessType: [
          { required: true, message: "请选择", trigger: "change" },
        ],
        industyCode: [{ required: true, message: "请选择", trigger: "change" }],
        linkManName: [
          { required: true, message: "请输入联系人姓名", trigger: "blur" }
        ],
        linkManIdcard: [
          { required: true, message: "请输入身份证号", trigger: "blur" },
        ],
        legalName: [
          { required: true, message: "请输入法人姓名", trigger: "blur" }
        ],
        legalIdcard: [
          { required: true, message: "请输入法人身份证号", trigger: "blur" },
        ],
        socialCreditCode: [
          {
            required: true,
            message: "请输入社会统一信用代码",
            trigger: "blur",
          },
          {
            min: 18,
            max: 18,
            message: "社会信统一用代码为企业唯一标识，请谨慎填写",
            trigger: "blur",
          },
          // { validator: validatorUser, message: '社会信统一用代码为企业唯一标识，请谨慎填写'}
        ],
        linkIdcardFrondUrl: [
          {
            required: true,
            message: "请上传联系人身份证正面",
            trigger: "blur",
          },
        ],
        linkIdcardBackUrl: [
          {
            required: true,
            message: "请上传联系人身份证反面",
            trigger: "blur",
          },
        ],
        legalIdcardFrondUrl: [
          {
            required: true,
            message: "请上传法人身份证正面",
            trigger: "blur",
          },
        ],
        legalIdcardBackUrl: [
          {
            required: true,
            message: "请上传法人身份证反面",
            trigger: "blur",
          },
        ],
        licenseUrl: [
          { required: true, message: "请上传营业执照", trigger: "blur" },
        ],
        agreementUrl: [
          { required: true, message: "请上传合同", trigger: "blur" },
        ],
        // bankNo: [
        //   { required: true, message: "请输入开户账号", trigger: "blur" },
        // ],
      },
      codeMessage: '发送验证码',
      timeNumber: null,
      uploadType: false,
      registerId: null
    };
  },
  created() {
    // console.log(this.nextStep)
    // this.login();
    this.socialCreditCode();
    // if(localStorage.getItem("nextStep") != null){
    this.nextStep = localStorage.getItem("nextStep");
    //   // localStorage.removeItem("nextStep");
    // }
    if(localStorage.getItem("nextSteps") != null){
      this.nextSteps = localStorage.getItem("nextSteps");
      // localStorage.removeItem("nextSteps");
    }
    if(localStorage.getItem("businessPo") != null){
      this.businessPo = JSON.parse(localStorage.getItem("businessPo"));
    }

  },
  computed: {
    collapse() {
      return this.$store.state.collapse;
    }
  },
  methods: {
    seeEye(){
      this.seeEyeShow = false
      this.passwordShow =  "text"
    },
    seeEyes(){
      this.seeEyeShow = true
      this.passwordShow =  "password"
    },
    // 校验登录账号
    checkBlur(e) {
      let platformNo = localStorage.getItem("platformNo").replace("\"","").replace("\"","");
      this.$http({
        url: "/api/quick/consumer/checkBusinessLoginName?businessLoginName=" + e.target.value,
        method: "post",
        headers: {
          "Content-Type": "application/json",
          "platformNo": platformNo
        },
      }).then((data) => {
        if(data.result == 1){
          this.$message.error('用户名已存在');
        }
        this.businessLoginName = data.result
      });
    },
    // 校验公司名称
    checkBlurs(e) {
      let platformNo = localStorage.getItem("platformNo").replace("\"","").replace("\"","");
      this.$http({
        url: "/api/quick/consumer/checkBusinessName?businessName=" + e.target.value,
        method: "post",
        headers: {
          "Content-Type": "application/json",
          "platformNo": platformNo
        },
      }).then((data) => {
        if(data.result == 1){
          this.$message.error('公司名称已注册');
        }
        this.businessName = data.result
      });
    },
    handleAvatarSuccess( file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg';
      const isPNG = file.type === 'image/png';
      const isLt6M = file.size / 1024 / 1024 < 6;
      if (!isJPG && !isPNG) {
        this.$message.error('上传头像图片只能是 JPG和PNG 格式!');
      }
      if (!isLt6M) {
        this.$message.error('上传头像图片大小不能超过 6MB!');
      }
      return isJPG && isLt6M;
    },
    // 审核成功跳转登录
    socialCreditCode(){
      localStorage.setItem("socialCreditCode", this.ruleBusiness.socialCreditCode);
      if(localStorage.getItem("socialCreditCode")){
        this.$http({
          url: "/api/quick/oem/business/getBusinessinfoBySocialID?socialCreditCode=" + this.ruleBusiness.socialCreditCode,
          method: "post",
          headers: {
            "Content-Type": "application/json",
          },
        }).then((data) => {
          if (data.code == 0) {
            if(data.result.isDisable == 1){
              if(data.result.checkStatus == 3){
                this.$router.push("/Login");
                localStorage.removeItem("socialCreditCode");
              }
            }
          }
        });
      }
    },
    login(){
        this.$http({
          url: "/api/quick/consumer/selectPlatformLogoAndName",
          method: "post",
          headers: {
            "Content-Type": "application/json",
          },
        }).then((data) => {
          if (data.code == 0) {
            this.logoUrl = data.result.logoUrl
            this.platformName = data.result.name
            if(!data.result.industyCode){
              localStorage.setItem("nextStep", 1);
              localStorage.setItem("nextSteps", 0);
            }
          }
        });
    },
    // 校对验证码
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
            // this.ruleForm.password = Encrypt(this.ruleForm.password);
            // this.ruleForm.confirmPassword = Encrypt(this.ruleForm.confirmPassword);
            this.ruleForms.username = this.ruleForm.username;
            this.ruleForms.phone = this.ruleForm.phone;
            this.ruleForms.smsCode = this.ruleForm.smsCode;
            this.ruleForms.password = Encrypt(this.ruleForm.password);
            this.ruleForms.confirmPassword = Encrypt(this.ruleForm.confirmPassword);
          // if(this.businessLoginName == 0){
            if (this.ruleForm.password == this.ruleForm.confirmPassword) {
              // this.nextStep = 2;
              // this.$http({
              //   url: "/api/quick/verification/verificationCode",
              //   method: "post",
              //   headers: {
              //     "Content-Type": "application/json",
              //   },
              //   data: {
              //     phone: this.ruleForm.phone,
              //     smsCode: this.ruleForm.smsCode
              //   },
              // }).then((data) => {
              //   if (data.code == 0) {
              //     this.nextStep = 2;
              //   }else {
              //     this.$message.error("验证码验证失败");
              //   }
              // });
               this.$http({
                url: "/api/quick/consumer/businessRegister",
                method: "post",
                headers: {
                  "Content-Type": "application/json",
                },
                data: this.ruleForms,
                // data: {
                //   phone: this.ruleForm.phone,
                //   smsCode: this.ruleForm.smsCode,
                //   username: this.ruleForm.username,
                //   password: this.ruleForm.password,
                //   confirmPassword: this.ruleForm.confirmPassword,
                // },
              }).then((data) => {
                if (data.code == 0) {
                  this.$http({
                    url: "/api/quick/consumer/doLogin",
                    method: "post",
                    headers: {
                      "Content-Type": "application/json",
                    },
                    data: {
                      username: this.ruleForm.username,
                      password: Encrypt(this.ruleForm.password),
                    },
                  }).then((data) => {
                    if (data.code == 0) {
                      // businessId
                      this.nextStep = 2;
                      this.$store.commit("updateToken", data.result)
                      localStorage.setItem("bussines_token", data.result.access_token);
                      localStorage.setItem("bussines_info", JSON.stringify(data.result.consumerDto));
                      // this.$message.success("登录成功");
                      // if(data.result.checkStatus == 1){
                      //   this.$router.push("/register");
                      //   localStorage.setItem("nextStep", 3);
                      //   localStorage.setItem("nextSteps", 3);
                      // }else if(data.result.checkStatus == 2) {
                      //   localStorage.setItem("nextStep", 3);
                      //   localStorage.setItem("nextSteps", 2);
                      //   localStorage.setItem("businessPo", JSON.stringify(data.result.businessPo));
                      //   this.$router.push("/register");
                      // }else if (data.result.checkStatus == 3) {
                      //   localStorage.removeItem("nextStep");
                      //   localStorage.removeItem("nextSteps");
                      //   this.$router.push("/");
                      // }
                    }
                  });
                }else {
                  this.$message.error("验证码验证失败");
                }
              });
              
            }else {
              this.$message.error("两次密码输入不一致");
            }
          } else {
            // this.$message.error('用户名已存在')
          }
        // } else {
        //   return false;
        // }
      });
    },
    examine(formName) {
      // 申请审核注册
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if(this.businessName == 0){
            this.ruleBusiness.businessTypeMsg = this.$refs.businessType.selectedLabel;
            this.ruleBusiness.industyMsg = this.$refs.industy.selectedLabel;
            this.ruleForm.password = Encrypt(this.ruleForm.password);
            // this.ruleBusiness.password = Encrypt(this.ruleBusiness.password);
            if(this.registerId === null) {
              // 正常注册流程
              this.$http({
                // url: '/api/quick/consumer/doRegister',
                url: '/api/quick/oem/business/initBusinessInfo',
                method: "post",
                headers: {
                  "Content-Type": "application/json",
                },
                // data: {
                //   businessPo: this.ruleBusiness,
                //   consumerInfoPo: this.ruleForm
                // },
                data: this.ruleBusiness,
              }).then((data) => {
                if (data.code == 0) {
                  this.nextStep = 3
                  this.nextSteps = 3
                  localStorage.setItem("nextStep", 3);
                  localStorage.setItem("nextSteps", 3);
                  // this.$router.push({name: 'login'});
                }
              });
            }else {
              let d = Object.assign({}, this.ruleBusiness)
              d['id'] = this.registerId
              this.$http({
                url: '/api/quick/consumer/updateBusiness',
                method: "post",
                headers: {
                  "Content-Type": "application/json",
                },
                data: d,
              }).then((data) => {
                if (data.code == 0) {
                  this.nextStep = 3
                  this.nextSteps = 3
                  // this.$router.push({name: 'login'});
                }
              });
            }
          } else {
            this.$message.error('公司名称已注册')
          }
        } else {
          if (this.nextStep == 2) {
            this.nextStep = 2;
          }
        }
      });
    },
    handleChangeFile(file) {
      this.fileData = file;
    },
    handleRemove(name) {
      this.$refs[name].clearFiles();
    },
    getNextStep(){
      this.nextStep = 2;
      // this.ruleBusiness.bankName = this.businessPo.bankName;
      // this.ruleBusiness.bankNo = this.businessPo.bankNo;
      this.ruleBusiness.name = this.businessPo.name;
      this.ruleBusiness.businessType = this.businessPo.businessType * 1;
      this.ruleBusiness.businessTypeMsg = this.businessPo.businessTypeMsg;
      this.ruleBusiness.industyCode = this.businessPo.industyCode * 1;
      this.ruleBusiness.industyMsg = this.businessPo.industyMsg;
      this.ruleBusiness.licenseUrl = this.businessPo.licenseUrl;
      this.ruleBusiness.agreementUrl = this.businessPo.agreementUrl;
      this.ruleBusiness.qualAttachmentUrl = this.businessPo.qualAttachmentUrl;
      this.ruleBusiness.linkIdcardFrondUrl = this.businessPo.linkIdcardFrondUrl;
      this.ruleBusiness.linkIdcardBackUrl = this.businessPo.linkIdcardBackUrl;
      this.ruleBusiness.legalIdcardFrondUrl = this.businessPo.legalIdcardFrondUrl;
      this.ruleBusiness.legalIdcardBackUrl = this.businessPo.legalIdcardBackUrl;
      this.ruleBusiness.legalName = this.businessPo.legalName;
      this.ruleBusiness.legalIdcard = this.businessPo.legalIdcard;
      this.ruleBusiness.linkManName = this.businessPo.linkManName;
      this.ruleBusiness.linkManIdcard = this.businessPo.linkManIdcard;
      this.ruleBusiness.socialCreditCode = this.businessPo.socialCreditCode;
      this.registerId = this.businessPo.id
      this.fileList.licenseUrl.push({name: '1.png', url: this.businessPo.licenseUrl})
      this.fileList.linkIdcardFrondUrl.push({name: '1.png', url: this.businessPo.linkIdcardFrondUrl})
      this.fileList.linkIdcardBackUrl.push({name: '1.png', url: this.businessPo.linkIdcardBackUrl})
      this.fileList.agreementUrl.push({name: '1.png', url: this.businessPo.agreementUrl})
      if(this.ruleBusiness.legalIdcardFrondUrl) {
        this.fileList.legalIdcardFrondUrl.push({name: '1.png', url: this.businessPo.legalIdcardFrondUrl})
      }
      if(this.ruleBusiness.legalIdcardBackUrl) {
        this.fileList.legalIdcardBackUrl.push({name: '1.png', url: this.businessPo.legalIdcardBackUrl})
      }
      if(this.ruleBusiness.qualAttachmentUrl) {
        this.fileList.qualAttachmentUrl.push({name: '1.png', url: this.businessPo.qualAttachmentUrl})
      }
    },
    sendCode() {
      // 获取验证码
      this.$http({
        url: "/api/quick/verification/sendCode",
        method: "post",
        headers: {
          "Content-Type": "application/json",
        },
        data: {
          phone: this.ruleForm.phone,
        },
      }).then((data) => {
        if (data.code == 0) {
          let num = 60
          this.timeNumbers = true
          this.timeNumber = setInterval(() => {
            if(num == 0) {
              this.timeNumbers = false
              this.codeMessage = '获取验证码'
              clearInterval(this.timeNumber)
              this.timeNumber = null
              return false
            }
            this.codeMessage = num-=1
          }, 1000);
        }
      });
    },
    uploadPhotoFile(res, key) {
      // 文件上传公用
      let formData = new FormData();
      formData.append("file", res.file);
      const isLt6M = res.file.size / 1024 / 1024 < 6;
      if (!isLt6M) {
        this.$message.error('上传头像图片大小不能超过 6MB!');
      }else {
        this.$http({
          url: "/api/quick/oss/uploadBySingle",
          method: "post",
          headers: {
            "Content-Type": "multipart/form-data",
          },
          data: formData,
        }).then((data) => {
          if (data.code == 0) {
            this.ruleBusiness[key] = data.result;
            if(res.file.type == "application/pdf" && key == "agreementUrl") {
              this.uploadType = true
            }else {
              this.uploadType = false
            }
          }
        });
      }
    },
    removePhotoFile(name, key) {
      // 删除文件
      this.$refs[name].clearFiles();
      this.ruleBusiness[key] = "";
      this.fileList[key] = []
      // this.$http({
      //   url: "/api/quick/oss/deleteFileBySingle?fileUrl=" + this.ruleBusiness[key],
      //   method: "post",
      //   headers: {
      //     "Content-Type": "multipart/form-data",
      //   },
      // }).then((data) => {
      //   if (data.code == 0) {
      //     this.$refs[name].clearFiles();
      //     this.ruleBusiness[key] = "";
      //   }
      // });
    },
  },
  
};
</script>
<style scoped>
html,
body {
  overflow: inherit;
}
.examine b a {
    display: block;
    font-size: 16px;
    font-weight: normal;
    color: #03a1ff;
    cursor: pointer;
    margin-top: 10px;
    padding: 5px 0;
}
.registerLogo img {
  width: 180px;
  height: 50px;
}
.register {
  width: 100%;
  background: #eef4fb;
  float: left;
  height: 100%;
  overflow-y: scroll;
}
.registerLogo {
  margin: 30px 0 30px 10%;
  font-size: 28px;
  color: #5b7da0;
}
.registerCon {
  width: 80%;
  float: left;
  margin: 0 10% 50px;
  background: #fff;
  box-shadow: 0px 4px 6px 0px #e1efff;
  border-radius: 10px;
}
.login-btn {
  text-align: center;
  margin: 100px 0 50px -90px;
}
.login-btn button {
  width: 220px;
  height: 40px;
}
.login-btn b {
  font-size: 12px;
  color: #95a8be;
  display: block;
  text-align: center;
  margin-top: 10px;
  font-weight: normal;
  line-height: 1;
  height: 12px;
}
.login-btn a {
  color: #326cf0;
}
.tregisterTab {
  margin: 40px 5% 70px;
}
.tregisterTab ul li {
  float: left;
  width: 33.33%;
  text-align: center;
  font-size: 18px;
  color: #95a8be;
  line-height: 70px;
  height: 70px;
  position: relative;
  overflow: hidden;
}
.tregisterTab ul li > div {
  position: relative;
  z-index: 11;
}
.tregisterTab ul li img {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 70px;
}
.tregisterTab ul li img.on {
  display: none;
}
.tregisterTab ul li.active img.on {
  display: block;
}
.tregisterTab ul li.active {
  color: #fff;
}
.tregisterTab ul li span {
  width: 30px;
  height: 30px;
  background: #b9c7d6;
  text-align: center;
  border-radius: 100%;
  display: inline-block;
  line-height: 30px;
  margin-right: 20px;
}
.tregisterTab ul li.active span {
  color: #326cf0;
  background: #fff;
}
.suffix-button {
  width: 90px;
  height: 26px;
  background: #ffffff;
  border-radius: 4px;
  border: 1px solid #326cf0;
  color: #326cf0;
  font-size: 12px;
  cursor: pointer;
  line-height: 26px;
  margin: 6px 33px 0 0;
}
.suffix-button.on {
  cursor: pointer;
  pointer-events: none;
}
.seeEye {
  position: absolute;
  width: 20px;
  right: 30px;
  top: 12px;
  cursor: pointer;
}
</style>

